import PlayGroundCanvas from "../playground/backgroundCanvas";
import StructElement from "./StructElement";
import { IStructInitInfo } from "./type";

const AllElements = new Map<IStructInitInfo,Array<StructElement>>();
export default class StructElementMgr{
    private static selfTarget:StructElementMgr;
    private constructor(){

    }
    static getInstance(){
        if(!this.selfTarget)
            this.selfTarget = new StructElementMgr();
        return this.selfTarget;
    }
    createElement(structInfo:IStructInitInfo,container: HTMLElement, playGround: PlayGroundCanvas, initTop: number = 2,
        initLeft: number = 2,
        initWidth: number = 3,
        initHeight: number = 2){
            const newElement = new StructElement(container,playGround,
                structInfo.top || initTop,
                structInfo.left || initLeft,
                structInfo.width || initWidth,
                structInfo.height || initHeight);
            const structs = AllElements.get(structInfo) || [];
            structs.push(newElement);
            newElement.active();
            AllElements.set(structInfo,structs);
    }
    getStructElement(structInfo?:IStructInitInfo){
        if(structInfo){
            return AllElements.get(structInfo);
        }else{
            return Array.from(AllElements.entries());
        }
        
    }
    getAllStructElmenet(){
        return Array.from(AllElements.entries());
    }
}